﻿<splx:SplxUserControl x:Class="SuplexApp.FillMapCtrl"
                   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                   xmlns:local="clr-namespace:SuplexApp"
                   xmlns:splx="clr-namespace:Suplex.Wpf;assembly=Suplex.Wpf"
                   KeyDown="fmEditor_KeyDown">
    <UserControl.Resources>
        <local:FormattingConverter x:Key="formatter" />
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot">
        <Grid.ColumnDefinitions>
            <ColumnDefinition MaxWidth="700" MinWidth="150"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid HorizontalAlignment="Stretch">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>

            <StackPanel Orientation="Horizontal">
                <TextBlock Margin="5,5,0,5" FontSize="14" FontWeight="Bold" VerticalAlignment="Center" Foreground="DarkBlue"
                           TextBlock.Text="Fill Map: "/>
                <TextBlock Margin="0,5,0,5" FontSize="14" FontWeight="Bold" VerticalAlignment="Center"
                           TextBlock.Text="{Binding Path=Name}"/>
                <TextBlock Margin="0,5,0,5" FontSize="18" FontWeight="Bold" VerticalAlignment="Top" Foreground="Red"
                           TextBlock.Text="*"
                           Visibility="{local:FormattedBinding Path=IsDirty, ValueIfTrue=Visible, ValueIfFalse=Hidden}"/>
            </StackPanel>
            <StackPanel HorizontalAlignment="Right" Orientation="Horizontal" Grid.Column="1" Margin="0,0,5,0">
                <Button Name="cmdOk" Content="Save"
                        VerticalAlignment="Center" MinHeight="20" Padding="5,0,5,0"
                        IsEnabled="{local:FormattedBinding Path=IsDirty}"
                        Click="cmdOk_Click"/>
                <Button Name="cmdCancel" Content="Discard"
                        VerticalAlignment="Center" MinHeight="20" Padding="5,0,5,0" Margin="5,0,0,0"
                        Click="cmdCancel_Click"/>
            </StackPanel>
        </Grid>
        <ScrollViewer VerticalScrollBarVisibility="Auto" Grid.Row="1" Background="White">
            <GroupBox Grid.Row="0" Margin="0,0,0,3" Header="Properties">
                <Grid Margin="5,0,5,0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition MinWidth="150"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <Label Grid.Column="0" Grid.Row="0" Content="Name:" Style="{DynamicResource DialogLabel}" />
                    <splx:SplxTextBox Grid.Column="1" Grid.Row="0" Name="txtName" Style="{DynamicResource DialogTextBox}"
                                   Text="{Binding Path=Name, UpdateSourceTrigger=PropertyChanged}"/>

                    <Label Grid.Column="0" Grid.Row="1" Content="Expression:" VerticalAlignment="Top" Style="{DynamicResource DialogLabel}" />
                    <splx:SplxTextBox Grid.Column="1" Grid.Row="1" Name="txtExpression" Style="{DynamicResource DialogTextBox}"
                                   MinLines="5" AcceptsReturn="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto"
                                   Text="{Binding Path=Expression, UpdateSourceTrigger=PropertyChanged}" />

                    <Label Grid.Column="0" Grid.Row="2" Content="Expression Type:" Style="{DynamicResource DialogLabel}" />
                    <splx:SplxComboBox Grid.Column="1" Grid.Row="2" Name="cmbExpressionType" Style="{DynamicResource DialogControl}"
                                       IsEditable="False" IsReadOnly="False"
                                       SelectedItem="{Binding Path=ExpressionType}"/>

                    <Label Grid.Column="0" Grid.Row="3" Content="Event Binding:" Style="{DynamicResource DialogLabel}" />
                    <Grid Grid.Column="1" Grid.Row="3">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition />
                            <ColumnDefinition Width="75"/>
                            <ColumnDefinition Width="50"/>
                        </Grid.ColumnDefinitions>

                        <splx:SplxComboBox Grid.Column="0" Name="cmbEventBinding" Style="{DynamicResource DialogControl}"
                                           SelectedItem="{Binding Path=EventBinding}"/>

                        <Label Grid.Column="1" Content="Sort Order:" Style="{DynamicResource DialogLabel}" />
                        <splx:SplxTextBox Grid.Column="2" Name="txtSortOrder" Style="{DynamicResource DialogTextBox}"
                                          Text="{Binding Path=SortOrder, UpdateSourceTrigger=PropertyChanged}"/>
                    </Grid>

                    <Label Grid.Column="0" Grid.Row="4" Content="Data Bindings:" VerticalAlignment="Top" Style="{DynamicResource DialogLabel}" />
                    <DataGrid Grid.Column="1" Grid.Row="4" MinHeight="200" Name="dgDataBindings"
                              VerticalAlignment="Top"  AutoGenerateColumns="False"
                              BeginningEdit="dgDataBindings_BeginningEdit" CellEditEnding="dgDataBindings_CellEditEnding"
                              ItemsSource="{Binding Path=DataBindings}">
                        <DataGrid.Columns>
                            <DataGridTextColumn Binding="{Binding Path=ControlName}" Header="Control Name" />
                            <DataGridTextColumn Binding="{Binding Path=PropertyName}" Header="Property" />
                            <DataGridTextColumn Binding="{Binding Path=DataMember}" Header="Value" />
                            <DataGridCheckBoxColumn Binding="{Binding Path=OverrideValue}" Header="Override Existing Value" />
                        </DataGrid.Columns>
                    </DataGrid>

                    <splx:ValidationSummary Name="vs" Grid.Column="1" Grid.Row="5" MaxHeight="100" />
                </Grid>
            </GroupBox>
        </ScrollViewer>
    </Grid>
</splx:SplxUserControl>